package com.projeto.desafio.dao;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class ServiceLocator {
	private static final Context CONTEXT;

	static {
		try {
			CONTEXT = new InitialContext();
		} catch (NamingException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
	}

	@SuppressWarnings("unchecked")
	public static <T> T lookup(String jndiName) {
		try {
			return (T) CONTEXT.lookup(jndiName);
		} catch (NamingException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
	}
}
